package com.mindao.app.es.rest;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mindao.app.common.spring.controller.BaseController;
import com.mindao.app.common.spring.service.BaseService;
import com.mindao.app.es.model.EsTeam;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：
/*
/* 创 建 人：李国才
/* 创建时间：2016年6月16日 下午1:03:24 	
 **/
@Controller
@RequestMapping("/es/esteamrest")
public class EsTeamRestController extends BaseController<EsTeam> {
	@javax.annotation.Resource(name = "baseService")
	private BaseService baseService;
	/**加载team数据，应该分页读取，这里只是测试
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping//(method = RequestMethod.POST)
	public String teamsAjax(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception{
		String pageId=super.getpara("pageId");
		pageId=(pageId==null||"".equals(pageId))?"1":pageId;
		System.out.println("当前页："+pageId);
//		List<EsTeam> list=new ArrayList<>();
//		for (int i=0;i<20;i++){
//			EsTeam t=new EsTeam();
//			t.setName("战队名称"+(((Integer.valueOf(pageId)-1)*20)+i+1));
//			list.add(t);
//		}
//		rhs.addAttribute("dataList", list);
		return super.searchPageAjax(request, response, session, rhs);
	}
	
	/**加载team数据，应该分页读取，这里只是测试
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping//(method = RequestMethod.POST)
	public String teams(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception{
		String pageId=super.getpara("pageId");
		pageId=(pageId==null||"".equals(pageId))?"1":pageId;
		System.out.println("当前页："+pageId);
 
		return super.searchPageAjax(request, response, session, rhs);
	}
	
	
	@RequestMapping 
	public String init(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs){
		List<EsTeam> list2=baseService.find("from EsTeam");
		for (EsTeam t:list2) {
			baseService.deletePhsically(t);
		}
		List<EsTeam> list=new ArrayList<>();
		for (int i=1;i<=200;i++){
			EsTeam t=new EsTeam();
			t.setName("第"+i+"号战队");
			baseService.create(t);
		}
		rhs.addAttribute("dataList", list);
		return super.rtnDefault(request, response, session, rhs);
	}
}
